setInterval("checkNewMessage()", 15000);
var notifikasi = new Array();

function checkNewMessage()
{
    
    $.ajax({
          type  : 'GET',
          dataType: 'json',
          url   : '/pesanNotifikasi/check',
          success: function(data, textStatus, jqXHR){ 
             
             if(!jQuery.isEmptyObject(data.result))
                 {
                    $.each(data.result, function(i, v){ 
                
                        if(!notifikasi.hasOwnProperty(v.id))
                        {
                            notifikasi[v.id] = noty({
                                    dismissQueue: true,
                                    modal: false,
                                    text: '<div style="font-size:10px">'+v.created_date+'</div>'+v.notifikasi,
                                    animation: {
                                        open: {height: 'toggle'},
                                        close: {height: 'toggle'},
                                        easing: 'swing',
                                        speed: 500 // opening & closing animation speed
                                    },
                                    type: 'information',
                                    layout: 'topRight',
                                    closeWith: ['click'],
                                    callback: {
                                        onShow: function() {},
                                        afterShow: function() {},
                                        onClose: function() {
                                            $.ajax({
                                                type  : 'GET',
                                                dataType: 'json',
                                                url   : '/pesanNotifikasi/update/'+v.id,
                                                success: function(data, textStatus, jqXHR){
                                                    if(v.id_pegawai!=''){
                                                        window.location.replace(v.url);
                                                    }
                                                }
                                            });

                                        },
                                        afterClose: function() {}
                                    }
                            });

                        }

                    });
                 }
             
             
          }
    });
}